using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Comteck.Domain.Entities;

namespace Comteck.Ktt.Services.Infrastructure {
  public interface IKttRepository<TEntity, TKey> where TEntity : class, IEntity<TKey> {

    /// <summary>
    /// 
    /// </summary>
    DbContext DbContext { get; }

    //
    // 摘要:
    //     Returns the queryable entity set for the given type {T}.
    //
    // 返回结果:
    //     IQueryable to be used to select entities from database
    IQueryable<TEntity> Table { get; }

    //
    // 摘要:
    //     Returns an untracked queryable entity set for the given type {T}. The entities
    //     returned will not be cached in the object context thus increasing performance.
    //
    //
    // 返回结果:
    //     IQueryable to be used to select entities from database
    IQueryable<TEntity> TableUntracked { get; }

    Task<TEntity> GetByIdAsync(TKey id);
    Task<IEnumerable<TEntity>> GetAllAsync();
    Task<IEnumerable<TEntity>> FindAsync(Expression<Func<TEntity, bool>> predicate);

    Task AddAsync(TEntity entity);
    Task AddRangeAsync(IEnumerable<TEntity> entities);

    Task UpdateAsync(TEntity entity);
    Task UpdateRangeAsync(IEnumerable<TEntity> entities);

    Task RemoveAsync(TEntity entity);
    Task RemoveRangeAsync(IEnumerable<TEntity> entities);

    Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate);
    Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate);

    Task<int> SaveChangesAsync();
  }
}
